<?php
namespace app\ajax\controller;
class Auto extends Base
{
  public function initialize()
    {
        parent::initialize();
        
     }
   //定时检测自动确认验收 
  public function index(){


          if($this->request->isAjax()){
                  //判断自动确认是否开启
                  if($this->settings['guarantee']['auto_confirm_status'] ==1){
                    $where[] = ['shipping_status','=',1];
                    $where[] = ['auto_confirm_time','>',0]; //自动确认时间存在
                    $order =  model('guarantee')->listData($where); 
                     foreach($order as $k=>$v){
                              if($v['auto_confirm_time'] < time()){
                                $data =[];
                                $data['shipping_status'] = 2; //收货状态

                                $data['buyer_evaluate'] = 1; //默认好评
                                $data['buyer_evaluate_content'] = '好评';
                                $data['buyer_evaluate_time'] = time();

                                $where=[];
                                $where['id'] = $v['id'];

                                model('guarantee')->editData($data,$where);
                                // 给卖家打款
                                model('user')->payin($v['seller_uid'],$v['seller_get'],'自动确认验收，获得收入'.$v['seller_get'].'元',"余额");
                                

                              }
                        
                        }
                  }
                  return success_json('success');
          }else{
            return error_json('请求错误');
          }
 
  }

 
}